package com.cli.springboot2study.util;

import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;

/**
 * <p>资源配置工具类</p>
 * <pre>
 * 声明式配置注入：
 * 方式一：
 *      {@code @Component }
 *      {@code @ConfigurationProperties(prefix="XXXX") }
 *
 *
 * 方式二：
 *      {@code @EnableConfigurationProperties(ClasName.class) }
 *      {@code @ConfigurationProperties(prefix="XXXX") }
 * </pre>
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/4/23 15:13
 */
public class PropertiesUtils {

    /**
     * 获取Resource下发文件资源
     * @param resourcePath      resources下的文件
     * @throws IOException
     */
    public static void parseProperties(String resourcePath) throws IOException {
        Properties properties = new Properties();
        InputStream resourceAsStream = PropertiesUtils.class.getClassLoader().getResourceAsStream(resourcePath);
        properties.load(resourceAsStream);
        /**
         * 获取配置文件的名字
         */
        Enumeration<?> enumeration = properties.propertyNames();
        while (enumeration.hasMoreElements()) {
            String strKey = (String) enumeration.nextElement();
            String strValue = properties.getProperty(strKey);
            System.out.println("key = " + strKey + " value = " + strValue);
            /**
             * TODO 封装到JavaBean
             */
        }

    }
}
